# code to estimate latent space models from pundits' following behavior
# model used in main manuscript is the one-dimensional model without clustering (>1 dimension, >1 cluster does not improve fit)
library(network)
library(sna)
library(statnet)
library(latentnet)

b <- 50000

set.seed(1111)

load("../data/pundits_follow_net.RData")

params_df <- data.frame(dim = c(1,1,1,1,2,2,2,2),
                       g = c(0,1,2,3,0,1,2,3))

for(i in 1:nrow(params_df)){
  
    dim <- params_df$dim[i]
    g <- params_df$g[i]
    
    message(paste0("running latent space for d = ",dim, " and G = ", g, " with burnin = ", b))
    
     pundits.space <- latentnet::ergmm(pundit.follow.net ~ 
                                        euclidean(d = dim, G = g)+
                                        edges +
                                        rsender+
                                        rreceiver, 
                                      control = control.ergmm(burnin = b,
                                                              threads = 4,
                                                             interval = 10),
                                      seed = 11111, 
                                      verbose = TRUE)
    save(pundits.space, file = paste0("../output/latent_spaces/pundits_lspace_d",dim,"_G",g,".RData"))

}
